/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package presentation;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Rectangle;
import javax.swing.*;

/**
 *
 * @author Andreu Marimon
 */
public class MainFrame extends JFrame {
    public static final int WIDTH = 800;
    private static final int HEIGHT = 600;

    private PresentationController _pController;
    private JLabel _message;
    private JPanel _main;

    public void clean() {
        changeScreen(new StartView(_pController));
    }

    public void showError(String error) {
        //_message.setText(error);
    }

    public void changeScreen(JPanel newScreen) {
        _main.removeAll();
        _main.setLayout(new BorderLayout());
        _main.add(newScreen, BorderLayout.CENTER);
        //_message.setText(null);
        //_main.add(_message, BorderLayout.SOUTH);
        this.setContentPane(_main);
        repaint();
        validate();
    }

    /*public void logIn() {
        JPanel login = new StartView(_pController);
        changeScreen (login);
    }*/

    public MainFrame(PresentationController pCtrl) {
        super("Nominalitzator 2011");
        super.addWindowListener(new ExitListener());
        _pController = pCtrl;
        this.setResizable(false);
        Dimension dim = getToolkit().getScreenSize();
        Dimension mides = new Dimension(WIDTH, HEIGHT);
        this.setBounds(new Rectangle((dim.width/2)-(mides.width/2), (dim.height/2)-(mides.height/2), mides.width, mides.height));
        setVisible(true);
        validate();

        //incialitzem el missatge
        /*_message = new JLabel();
        _message.setMaximumSize(new Dimension(800,100));
        _message.setHorizontalAlignment( SwingConstants.CENTER );
        _message.setFont(new Font(Font.SERIF, Font.BOLD, 18));
        _message.setBorder(BorderFactory.createLineBorder(Color.GREEN));*/

        // Assignar panell predeterminat
        _main = new JPanel();
        JPanel start = new StartView(_pController);
        _main.setLayout(new BorderLayout());
        //_main.add(_message, BorderLayout.SOUTH);
        _main.add(start, BorderLayout.CENTER);
        this.setContentPane(_main);
        this.repaint();
        this.validate();
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    }
}
